﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using AfterlifeLib.Input;

namespace AfterlifeLib.GameScreens.Menus
{
    public class BooleanMenuEntry : MenuEntry
    {
        private bool value;
        public bool Value
        {
            get { return value; }
        }

        public BooleanMenuEntry(string text, bool value)
            : base(text)
        {
            this.value = value;
        }

        public override void HandleInput(MenuScreen screen)
        {
            if (InputState.Accept)
            {
                SwitchValue();
            }
        }

        public override void Update(MenuScreen screen, bool isSelected, Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(screen, isSelected, gameTime);
        }

        public override void Draw(MenuScreen screen, Microsoft.Xna.Framework.Vector2 position, bool isSelected, Microsoft.Xna.Framework.GameTime gameTime)
        {
            Color color = isSelected ? SelectedColor : NormalColor;

            color = new Color(color.R, color.G, color.B, screen.TransitionAlpha);

            SpriteBatch spriteBatch = screen.ScreenManager.SpriteBatch;
            SpriteFont font = screen.ScreenManager.Font;

            Vector2 origin = new Vector2(0, font.LineSpacing / 2);

            spriteBatch.DrawString(font, Text, position, color, 0,
                                   origin, 1f, SpriteEffects.None, 0);

            spriteBatch.DrawString(font, value ? "On" : "Off", position + ValueOffset, color, 0, 
                                    origin, 1f, SpriteEffects.None, 0);
        }

        private void SwitchValue()
        {
            value = !value;
        }
    }
}
